/**
 * 通用工具函数
 * @author Lee
 */
const CODE = {
  SUCCESS: 200,
  PARAM_ERROR: 400, //参数错误
  USER_ACCOUNT_ERROR: 20001, //账号或密码错误
  USER_LOGIN_ERROR: 30001, //用户未登录
  BUSINESS_ERROR: 40001, //业务请求失败
  AUTH_ERROR: 401, //认证失败或TOKEN过期
};

module.exports = {
  success({data = "", msg = "ok", code = CODE.SUCCESS}) {
    return {
      data,
      msg,
      code,
    };
  },
  fail({data = "", msg = "error", code = CODE.BUSINESS_ERROR}) {
    return {
      data,
      msg,
      code,
    };
  },
  pager({
    pageSize = 1,
    pageNum = 10, //不传时的默认值
  }) {
    pageSize *= 1;
    pageNum *= 1;
    let skipIndex = (pageSize - 1) * pageNum; //跳到哪页
    return {
      page: {
        pageSize,
        pageNum,
      },
      skipIndex,
    };
  },
};
